package edu.hnnu.sport_event.service;

import edu.hnnu.sport_event.entity.Admin;
import edu.hnnu.sport_event.entity.User;
import edu.hnnu.sport_event.mapper.AdminMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AdminServiceImp implements AdminService {

    @Resource
    AdminMapper mapper;

    @Override
    public int login(User user) {
        Admin _admin = mapper.select(user.getUsername());
        // 登录失败,该用户未注册
        if (_admin == null) return -2;
        // 登录成功
        if (user.getPassword().equals(_admin.getPassword())) { return _admin.getId(); }
        // 登录失败，密码错误
        return -1;
    }

    public Admin getAdmin(int id) {
        return mapper.selectById(id);
    }

    public int update(Admin admin) {
        return mapper.update(admin);
    }

    public String getName(int id) {
        return mapper.selectNameById(id);
    }

}
